const index = require('../config/index.js')
// 创建订单
export function addOrder(data) {
  return new Promise((resolve, reject) => {
    wx.request({
      url: index.api + 'order/add',
      method: 'POST',
      data,
      header: {
        'Authrization': 'Bearer ' + index.token
      },
      success(res) {
        resolve(res)
      },
      fail(res) {
        reject(res)
      }
    })
  })
}
// 获取全部订单
export function getOrders() {
  return new Promise((resolve, reject) => {
    wx.request({
      url: index.api + 'orders',
      method: 'GET',
      header: {
        'Authrization': 'Bearer ' + index.token
      },
      success(res) {
        resolve(res)
      },
      fail(res) {
        reject(res)
      }
    })
  })
}
// 根据id获取订单
export function getOrderById(id) {
  return new Promise((resolve, reject) => {
    wx.request({
      url: index.api + `order/${id}`,
      method: 'GET',
      header: {
        'Authrization': 'Bearer ' + index.token
      },
      success(res) {
        resolve(res)
      },
      fail(res) {
        reject(res)
      }
    })
  })
}
// 修改订单状态
export function updateOrderStatus(id, data) {
  return new Promise((resolve, reject) => {
    wx.request({
      url: index.api + `order/status/update/${id}`,
      method: 'PUT',
      data,
      header: {
        'Authrization': 'Bearer ' + index.token
      },
      success(res) {
        resolve(res)
      },
      fail(res) {
        reject(res)
      }
    })
  })
}
export default {
  addOrder,
  getOrders,
  getOrderById,
  updateOrderStatus
}